/*
 * Part of knowledge engineering (ke) course work, 2010/11
 */
package se.bth.ke.firstfriend.model;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlAttribute;

/**
 *
 * @author nico.rehwaldt
 */
@MappedSuperclass
public class BookmarkableItem implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @XmlAttribute
    @GeneratedValue(strategy = GenerationType.AUTO)
    protected Long id;
    
    @JoinColumn(name="user_id")
    @ManyToOne
    protected User user;
    
    @ManyToOne
    protected Article article;
    
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdAt;
    
    public BookmarkableItem() {}

    public BookmarkableItem(Article article) {
        this.article = article;
        this.createdAt = new Date();
    }

    public Long getId() {
        return id;
    }

    /**
     * @return the user
     */
    public User getUser() {
        return user;
    }

    /**
     * @param user the owner to set
     */
    public void setUser(User user) {
        this.user = user;
    }

    /**
     * @return the article
     */
    public Article getArticle() {
        return article;
    }

    /**
     * @return the createdAt
     */
    public Date getCreatedAt() {
        return createdAt;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof BookmarkableItem)) {
            return false;
        }
        BookmarkableItem other = (BookmarkableItem) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }
}
